# def fun1():
#     a=10
#     # print(f"a={a}")
#     def fun2():
#         a=15
#         b=20
#         # print(f"a={a},b={b}")
#         return a+b
#     return fun2()
# res=fun1
# print(res)
# print(res())
# print("===================================================================================")
# def old_func():
#     print("旧的功能")
# def new_func(func):
#     def wrapper() :
#         print("权限验证")
#         func()
#     return wrapper
# new_f=new_func(old_func)
# new_f()
# print("===============================================================================")
# def insert():
#     print("添加用户信息")
# def delete():
#     print("删除用户信息")
# def wrapper(func):
#     def func1():
#         print("权限验证")
#         func()
#     return func1
# insert=wrapper(insert)
# delete=wrapper(delete)
# insert()
# delete()
# print("===============================================================================")
def get_monry(money):
    print(f"我有{money}元")
    def child_buy(toy,price):
        # global money
        # nonlocal 允许嵌套函数修改外部全局变量
        nonlocal  money
        money -= price
        print(f"买了{toy}，花了{price}元，还剩{money}元")
    return child_buy
child_buy =get_monry(1000)
child_buy("a",200)
child_buy("b",300)
print("=================================================================================")
